package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DsMajorMapper;
import com.ruoyi.system.domain.DsMajor;
import com.ruoyi.system.service.IDsMajorService;

/**
 * 专业Service业务层处理
 *
 * @author tyro
 * @date 2025-03-30
 */
@Service
public class DsMajorServiceImpl implements IDsMajorService
{
    @Autowired
    private DsMajorMapper dsMajorMapper;

    /**
     * 查询专业
     *
     * @param majorId 专业主键
     * @return 专业
     */
    @Override
    public DsMajor selectDsMajorByMajorId(Long majorId)
    {
        return dsMajorMapper.selectDsMajorByMajorId(majorId);
    }

    /**
     * 查询专业列表
     *
     * @param dsMajor 专业
     * @return 专业
     */
    @Override
    public List<DsMajor> selectDsMajorList(DsMajor dsMajor)
    {
        Long userId = SecurityUtils.getUserId();

        // 如果不是管理员，则添加学院过滤条件
        if(!SecurityUtils.isAdmin(userId)){ // 或使用 SecurityUtils.isAdmin(loginUser.getUser().getUserId())
            dsMajor.setCollegeId(SecurityUtils.getLoginUser().getCollegeId());
        }
        if (dsMajor.getCollegeId() == 0){
            return dsMajorMapper.selectDsMajorListAll(dsMajor);
        }
        return dsMajorMapper.selectDsMajorList(dsMajor);
    }

    /**
     * 查询专业列表
     *
     * @param dsMajor 专业
     * @return 专业
     */
    @Override
    public List<DsMajor> selectDsMajorListByCollegeId(DsMajor dsMajor)
    {
        return dsMajorMapper.selectDsMajorListByCollegeId(dsMajor);
    }

    /**
     * 新增专业
     *
     * @param dsMajor 专业
     * @return 结果
     */
    @Override
    public int insertDsMajor(DsMajor dsMajor)
    {
        return dsMajorMapper.insertDsMajor(dsMajor);
    }

    /**
     * 修改专业
     *
     * @param dsMajor 专业
     * @return 结果
     */
    @Override
    public int updateDsMajor(DsMajor dsMajor)
    {
        return dsMajorMapper.updateDsMajor(dsMajor);
    }

    /**
     * 批量删除专业
     *
     * @param majorIds 需要删除的专业主键
     * @return 结果
     */
    @Override
    public int deleteDsMajorByMajorIds(Long[] majorIds)
    {
        return dsMajorMapper.deleteDsMajorByMajorIds(majorIds);
    }

    /**
     * 删除专业信息
     *
     * @param majorId 专业主键
     * @return 结果
     */
    @Override
    public int deleteDsMajorByMajorId(Long majorId)
    {
        return dsMajorMapper.deleteDsMajorByMajorId(majorId);
    }
}
